package com.qingfeng.provide.controller;

import com.github.pagehelper.PageInfo;
import com.qingfeng.core.dao.qingfeng.MessageDao;
import com.qingfeng.core.data.ResultData;
import com.qingfeng.core.entity.qingfeng.Message;
import com.qingfeng.provide.constant.MyConstant;
import com.qingfeng.provide.service.MessageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: 消息
 * @author:LWY
 * @date: 2017/11/15 16:05
 * @modified:
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    MessageService messageService;
    @Autowired
    MessageDao messageDao;

    /**
     * 获取用户的消息
     *
     * @return
     */
    @RequestMapping("/")
    public ResultData get(HttpServletRequest request) {
        String user_id = request.getParameter("id");
        String pageNum = request.getParameter("pageNum");
        if (StringUtils.isEmpty(pageNum)) {
            pageNum = "1";
        }
        PageInfo<Message> pageInfo = messageDao.get(Integer.valueOf(pageNum), MyConstant.getPageSize(), user_id);
        ResultData resultData = new ResultData(ResultData.SUCCESS, "获取消息成功", pageInfo);
        return resultData;
    }
}
